<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid" id="div1">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <p style="color: #0070C0;text-align: center;font-size: large;font-weight: bold;">合同申请一览表</p><br>
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" style="text-align: center">
                        <div class="layui-inline">
                            询价书名称：
                            <div class="layui-input-inline">
                                <input type="text" name="code" id="code" autocomplete="off"  placeholder="询价书名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            状态：
                            <div class="layui-input-inline">
                                <!--<input type="text"  placeholder="物资名称" autocomplete="off" class="layui-input">-->
                                <select>
                                    <option value="">全部</option>
                                    <option value="未确定">未确定</option>
                                    <option value="待审">待审</option>
                                    <option value="驳回">驳回</option>
                                    <option value="废弃">废弃</option>
                                    <option value="通过">通过</option>
                                </select>
                            </div>


                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <!--<button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>-->
                            <button class="layui-btn" data-type="reload" id="search">查询</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table style="margin-left: 10px"  id="text" lay-filter="demo"></table>
                </div>

            </div>
        </div>
    </div>
</div>
<div id="div2">
    <table class="layui-table" style="text-align: center">
        <thead>
        <tr>
            <th colspan="6" style="text-align: center;font-size: 20px;font-weight: bold;">编制合同</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">合  同  号</td>
            <td style="width: 400px" id="contAppNum"></td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">签订日期</td>
            <td style="width: 400px">
                <input id="contDate" type="date" name="title" lay-verify="title" autocomplete="off" class="layui-input">
            </td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">合同类型</td>
            <td style="width: 400px"  id="contType">采购合同</td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">买        方</td>
            <td style="width: 400px" id="buyer">长沙北大青鸟有限公司</td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">卖        方</td>
            <td style="width: 400px" id="seller"></td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">采购类型</td>
            <td style="width: 400px" id="stockType"></td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">币        别</td>
            <td style="width: 400px" id="money">人民币</td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">汇        率</td>
            <td style="width: 400px">1</td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">税        率</td>
            <td style="width: 400px" id="taxRate">1</td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">付款条件</td>
            <td style="width: 400px"  colspan="3">
                <input id="payCond" type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input">
            </td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">验收时间</td>
            <td style="width: 400px">
                <input id="verifyDate" type="date" name="title" lay-verify="title" autocomplete="off" class="layui-input">
            </td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">合同总金额(元)</td>
            <td style="width: 400px" id="contPrice"></td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">运输费用负担</td>
            <td style="width: 400px">
                <select  id="transport">
                    <option value="供方">供方</option>
                    <option value="需方">需方</option>
                </select>
            </td>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">付款方式</td>
            <td style="width: 400px">
                <select  id="payWay">
                    <option value="托收承付">托收承付</option>
                    <option value="银行支票">银行支票</option>
                    <option value="银行本票">银行本票</option>
                    <option value="银行汇票">银行汇票</option>
                    <option value="委托收款">委托收款</option>
                    <option value="商业票据">商业票据</option>
                </select>
            </td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px" colspan="6">
                逾期违约：供方逾期交货的，应按逾期交货金额每日千分之2向需方支付违约金，逾期超过30天，需方有权解除合同。
            </td>
        </tr>
        <tr>
            <td colspan="6">            <p style="color: #0070C0;text-align: center;font-size: large;font-weight: bold;">提供产品</p><br>
                <table class="layui-table" style="margin-left: 10px"  id="text1" ></table></td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px">备注</td>
            <td  style="width: 400px" colspan="5" >
                <input id="remark" type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input">
            </td>
        </tr>
        <tr>
            <td style="background-color: #F2F2F2;font-weight: bold;width: 230px" colspan="6">
                合同模板说明:公司名称-长沙北大青鸟有限公司，有效日期-2015/10/01至2025/12/31。
            </td>
        </tr>
        </tbody>
        <input type="hidden" id="applyId" />
    </table>

    <button class="layui-btn" style="margin-left: 590px" onclick="LuRu()">录入</button>
    <button class="layui-btn" data-type="reload" onclick="location.reload()">返回</button>
    <p></p>
    <p></p>
    <p></p>
</div>
<div id="div3">
    <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <!--<table class="layui-table layui-form" id="test"></table>-->
                        <TABLE class="layui-table layui-form" style="LINE-HEIGHT: 30px" cellSpacing=1 cellPadding=0
                               width="100%" bgColor=#336699 borderColorLight=#006699 border=0>
                            <TBODY>
                            <TR>
                                <TD>
                                    <TABLE class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>
                                        <TBODY>
                                        <TR bgColor=#ffffff>
                                            <TD align=middle width="100%" bgColor=#ffffff colSpan=20
                                                height=22>
                                                <H2 style="color: #0070c0"><B>合同申请明细</B></H2>
                                            </TD>
                                        </TR>
                                        <TR class=t1>
                                            <TD width="20%">询价书名称：</TD>
                                            <TD class=t2 width="30%">
                                                <A href="javascript:alert('对应询价书详细')" id="enquireName3"></A>
                                            </TD>
                                            <TD width="20%">报价份数：</TD>
                                            <TD class=t2 width="30%" id="statQuote"></TD>
                                        </TR>
                                        <TR class=t1>
                                            <TD width="20%">最高报价（元）：</TD>
                                            <TD class=t2 width="30%" id="topQuote"></TD>
                                            <TD width="20%">最低报价（元）：</TD>
                                            <TD class=t2 width="30%" id="lowQuote"></TD>
                                        </TR>
                                        </TBODY>
                                    </TABLE>
                                </TD>
                            </TR>
                            </TBODY>
                        </TABLE>

                        <TABLE class="layui-table layui-form" style="LINE-HEIGHT: 30px" cellSpacing=1 cellPadding=0
                               width="100%" bgColor=#336699 borderColorLight=#006699 border=0>
                            <TBODY>
                            <TR>
                                <table id="tableContract" class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>

                                </table>
                                <TD>
                                    <table  class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>
                                        <tbody >
                                        <tr class=t1>
                                            <td align=middle><B>需求计划数量</B></td>
                                            <td align=middle id="orderNum"></td>
                                            <td align=middle><B>订货计划数量</B></td>
                                            <td align=middle id="dingHuoNum"></td>
                                        </tr>
                                        <tr class=t1>
                                            <td align=middle>总金额（元）</td>
                                            <td align=middle colspan="3" id="sumPrice"></td>
                                        </tr>
                                        <tr>
                                            <td align=middle>部长审核结果</td>
                                            <td style="text-align: center" id="leadAgree">
                                            </td>
                                            <td align=middle>部长审核意见</td>
                                            <td id="leadOpinion">
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </TD>
                            </TR>
                            </TBODY>
                        </TABLE>

                        <BR>
                        <div style="text-align: center">
                            <INPUT onclick="location.href='/contractmanager/bianzhilist.html' " type="button" value="返回">
                            <!--<button onclick="Chong()" id="chx">重新审批</button>-->
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script id="button" type="text/html">
    <a class="layui-btn layui-btn-xs" lay-event="open">打开</a>
    <a class="layui-btn layui-btn-xs" lay-event="update">编制合同</a>
</script>
<script>

    layui.use('table', function(){
        $("#div2").hide();
        $("#div3").hide();
        var table = layui.table;
        table.render({
            elem: '#text'  //html中渲染table的id
            , url: '/contractmanager/jieshilist'   //后台获取数据集合的地址
            , cellMinWidth: 80
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 1 //只显示 1 个连续页码
                , first: false//不显示首页
                , last: false //不显示尾页

            }, cols: [
                [
                    //表单显示的title以及返回的需要显示的数据，field值与获取集合中的类的字段名一致。
                    {field: 'id', title: '序号', align: 'center',width:80},
                    {field: 'code', title: '合同申请编号', align: 'center',width: 150},
                    {field: 'leadDate', title: '签订时间', align: 'center'},
                    {field: 'topQuote', title: '总金额', align: 'center'},
                    {fixed: 'right',  title: '操作', toolbar: "#button",align:'center', width:170}
                ]
            ]
        });
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event==='update'){
                $("#div2").show();
                $("#div1").hide();
                $("#div3").hide();
                $.ajax({
                    url: "/contractmanager/Apply_Xq",
                    data: {"id": data.id},
                    type: "GET",
                    success: function (result) {
                        $("#applyId").val(data.id);
                        $("#stockType").html(result.enquire.stock.stockType);
                        $("#seller").html(result.materials[0].suppliers[0].abbreviation);
                        $("#contPrice").html(result.enquire.stock.budget);
                        $("#contAppNum").html(result.contAppNum);
                        $("#remark").html(result.enquire.remark);
                        var orders=result.orders;
                        // alert(JSON.stringify(orders))
                        var tabel=layui.table
                            table.render({
                                elem: '#text1'  //html中渲染table的id
                                , data: result.orders  //后台获取数据集合的地址
                                , cols: [
                                    [
                                        //表单显示的title以及返回的需要显示的数据，field值与获取集合中的类的字段名一致。
                                        ,{field: 'materialCode', title: '物资编码', align: 'center'},
                                        {field: 'materialName', title: '物资名称', align: 'center'},
                                        {field: 'amount', title: '数量', align: 'center'},
                                        {field: 'unitPrice', title: '单价(含税)', align: 'center'},
                                        {field: 'sumPrice', title: '总计(元)', align: 'center'},
                                        {field: 'startDate', title: '到货期', align: 'center'}
                                    ]
                                ]
                            });

                        table.reload('text1');
                    }
                });
            }else if(obj.event==='open'){
                $("#div1").hide();
                $("#div2").hide();
                $("#div3").show();
                $.ajax({
                    url:'/contractmanager/findContAppById',
                    data:{"id":data.id},
                    type:'post',
                    success:function (result) {
                        $("#enquireName3").html(result.contAppNum);
                        $("#statQuote").html(result.statQuote);
                        $("#topQuote").html(result.topQuote);
                        $("#lowQuote").html(result.lowQuote);
                        $("#sumPrice").html(result.allSumPrice);
                        $("#leadAgree").html(result.leadAgree);
                        $("#leadOpinion").html(result.leadOpinion);
                        $("#id").val(result.id);
                        if(result.status==='废弃'){
                            $("#chx").hide()
                        }
                        $.ajax({
                            url:'/contractmanager/findContAppId',
                            data:{"id":result.id},
                            type:'post',
                            success:function (result1) {
                                $("#orderNum").html(result1.length);
                                let dinghuoNum=0.00;
                                for (let i=0;i<result1.length;i++) {
                                    dinghuoNum+=Number(result1[i].amount);
                                    $("#tableContract").append(
                                        "<TR class=T1>\n" +
                                        "                                                <TD noWrap align=middle colSpan=9>\n" +
                                        "                                                    物资\n" +
                                        "                                                    <B style='color: red'>"+(Number(i)+1)+" &nbsp;\n" +
                                        "                                                    </B><A href=\"javascript:alert('对应需求计划书详细')\" style='color: blue'>"+result1[i].materialName+"</A>\n" +
                                        "                                                    "+result1[i].amount+"个\n" +
                                        "                                                    <B>计划价（元/含税）</B>\n" +
                                        "                                                    \n" +
                                        "                                                    <A\n" +
                                        "                                                        href=\"javascript:alert('对应报价书详细')\"> 报价明细信息</A>&nbsp;&nbsp;\n" +
                                        "                                                </TD>\n" +
                                        "                                            </TR>\n" +
                                        "                                            <TR class=t1>\n" +
                                        "                                                <TD noWrap align=middle width=\"20%\">供应商编号</TD>\n" +
                                        "                                                <TD noWrap align=middle>数量</TD>\n" +
                                        "                                                <TD noWrap align=middle>单价<BR>（元/含税）</TD>\n" +
                                        "                                                <TD noWrap align=middle>运杂费<BR>（元）</TD>\n" +
                                        "                                                <TD noWrap align=middle>其它费用<BR>（元）</TD>\n" +
                                        "                                                <TD noWrap align=middle>总计<BR>（元）</TD>\n" +
                                        "                                                <TD noWrap align=middle>开始<BR>交货期</TD>\n" +
                                        "                                                <TD noWrap align=middle>结束<BR>交货期</TD>\n" +
                                        "                                            </TR>\n"+"                                            <TR class=t2>\n" +
                                        "                                                <TD style='text-align: center' width=\"20%\">"+result1[i].supplierId+"<BR></TD>\n" +
                                        "                                                <TD align=right>"+result1[i].amount+"<BR></TD>\n" +
                                        "                                                <TD align=right>"+result1[i].unitPrice+"<BR></TD>\n" +
                                        "                                                <TD style='text-align: center'  align=right>"+result1[i].mixPrice+"<BR></TD>\n" +
                                        "                                                <TD style='text-align: center'  align=right>"+result1[i].otherPrice+"<BR></TD>\n" +
                                        "                                                <TD style='text-align: center'  align=right>"+result1[i].totalPrice+"<BR></TD>\n" +
                                        "                                                <TD style='text-align: center' >"+result1[i].startDate+"<BR></TD>\n" +
                                        "                                                <TD style='text-align: center' >"+result1[i].endDate+"<BR></TD>\n" +
                                        "                                            </TR>")
                                }

                                $("#dingHuoNum").html(dinghuoNum);
                            }

                        })
                    }
                })
            }
        });
        $('#search').on('click', function(){
            table.reload('tableAll', {
                method : 'get',
                /*url:'/contractmanager/byName',//这个不写表示使用table中的请求*/
                where : {
                    code : $.trim($('#code').val()),
                },
                page : {
                    curr : 1
                }
            });
        });
    });
    function LuRu(){
        var contAppNum=$("#contAppNum").html();
        var contDate=$("#contDate").val();
        var contType=$("#contType").html();
        var payCond=$("#payCond").val();
        var verifyDate=$("#verifyDate").val();
        var transport=$("#transport").val();
        var payWay=$("#payWay").val();
        var buyer=$("#buyer").html();
        var seller=$("#seller").html();
        var stockType=$("#stockType").html();
        var money=$("#money").html();
        var taxRate=$("#taxRate").html();
        var contPrice=$("#contPrice").html();
        var remark=$("#remark").html();
        var applyId=$("#applyId").val();
        $.ajax({
            url: "/Cont/BianZhi",
            data: {
                "contNum": contAppNum,
                "contDate": contDate,
                "contType": contType,
                "payCond": payCond,
                "verifyDate": verifyDate,
                "transport": transport,
                "payWay": payWay,
                "buyer": buyer,
                "seller": seller,
                "stockType": stockType,
                "money": money,
                "taxRate": taxRate,
                "contPrice": contPrice,
                "remark": remark,
                "applyId":applyId,
                "Status":'未确定'
            },
            type: "GET",
            success: function (result) {
                layer.alert("编制成功!")
                location.reload()
            }
        });
    }
</script>


</html>